<template>
    <div style="width: 40%;margin-left: auto;margin-right: auto">
      <h2 style="color: grey">创建用户</h2><br>
      <el-form :model="form" status-icon  label-width="100px" class="demo-ruleForm" >
        <el-form-item label="姓名:" prop="u_name" >
          <el-input v-model="form.u_name" placeholder="请输入姓名"  type="text" style="width:95%"></el-input>
        </el-form-item>
        <el-form-item label="账号:" prop="u_acount">
          <el-input v-model="form.u_acount" placeholder="请输入账号" type="text" style="width:95%" oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="return false"></el-input>
        </el-form-item>
        <el-form-item label="身份:" prop="u_Identity">
          <el-select v-model="form.u_Identity" placeholder="请选择用户的身份" style="width:95%">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-button type="success" v-on:click="manaupdatepwd" plain>创建用户</el-button>
    </div>
</template>

<style>
    body {
        background-color: #fff;
    }
</style>

<script>
    export default {
      name:'createUser',
        data() {
            return {
              form:{
                u_name:'',
                u_acount:'',
                u_Identity:''
              },
           options: [{
             value: '1',
             label: '学生'
           }, {
             value: '2',
             label: '老师'
           }, {
             value: '3',
             label: '企业'
           }],
            }
        },
      methods:{
        manaupdatepwd:function () {

          this.$axios({
            url: `/api/user/manaCreateUser/` + "?u_name=" + this.form.u_name+"&u_acount="+this.form.u_acount+"&u_Identity="+this.form.u_Identity,
            method: 'get',
          }).then(teaInfoByCode => {  // 请求成功
            if(teaInfoByCode.data=="添加成功"){
              alert("添加成功!");
              location.reload();
            }else if(teaInfoByCode.data=="重复添加"){
              alert("账号已经存在!");
            }else {
              alert("服务器异常，请联系管理员!");
            }
          }).catch(error => {  // 请求失败

          });

        }
      },
    }
</script>
